﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Database;
namespace EFCodeFirstPerformanceTips
{
    public partial class MainForm : Form
    {
        public MainForm()
        {
            InitializeComponent();
            Method();
            //foreach (var currEmployee in employeeContext.Employees.Include("Department").AsNoTracking())
            //{
            //    MessageBox.Show(currEmployee.Name);
            //    MessageBox.Show(currEmployee.Department.Name);
            //}

            //var foundEmployee = employeeContext.Employees.Find(1);
            //employeeContext.Employees.Remove(foundEmployee);
            //employeeContext.SaveChanges();

            using (EmployeeContext employeeContext = new EmployeeContext())
            {
                var emps1 = employeeContext.Employees.Where(x => x.Name.StartsWith("S")).ToList();

               // var emps = employeeContext.Employees.Where(x => x.CreateDate < DateTime.Now.AddDays(-10)).ToList().Take(50);

                //foreach(Department dept in )
                //Employee stubEmpToDelete = new Employee() { ID = 1 };
                //employeeContext.Employees.Attach(stubEmpToDelete);
                //employeeContext.Employees.Remove(stubEmpToDelete);
                //employeeContext.SaveChanges();
            }
        }

        private void Method()
        {

            //employeeContext.Configuration.LazyLoadingEnabled = false;
            using (EmployeeContext employeeContext = new EmployeeContext())
            {
                var dept = new Department() { Name = "Dept1"};
                var employee = new Employee() { Name = "Sanjay Singh",  WageType = WageType.Daily, Address = new Database.Entities.Address() { City = "City", Street = "Street" }, Age = 30, Salary = 2000, Department = dept };
                employeeContext.Employees.Add(employee);
                employeeContext.Departments.Add(dept);
                employeeContext.SaveChanges();
            }
        }

        private void Method1()
        {

            using (EmployeeContext employeeContext = new EmployeeContext())
            {
                var employee = new Employee() { Name = "Tom", Age = 30, Salary = 2000 };
                employeeContext.Employees.Add(employee);
                employeeContext.SaveChanges();

                MessageBox.Show(employee.ID.ToString());
            }
        }
    }
}
